//
//  BNRReminderViewController.m
//  HypnoNerd
//
//  Created by zhaoxiaoyan on 16/12/23.
//  Copyright © 2016年 zhaoxiaoyan. All rights reserved.
//

#import "BNRReminderViewController.h"
//#import "UserNotifications/UNNotificationRequest.h"

@interface BNRReminderViewController ()

@property (nonatomic, strong) UIDatePicker *dataPicker;

@end

@implementation BNRReminderViewController

- (instancetype)init {
    self = [super init];
    if (self) {
//        UITabBarItem *tbi = self.tabBarItem;
//        tbi.title = @"Reminder";
        self.tabBarItem.title = @"Reminder";
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self drawDataPicker];
    [self drawButton];
}

- (void)drawDataPicker {
    self.dataPicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(10, 100, 355, 200)];
    self.dataPicker.backgroundColor = [UIColor lightGrayColor];
    self.dataPicker.date = [NSDate date]; // 设置初始时间
    //self.dataPicker.timeZone = [NSTimeZone timeZoneWithName:@"GMT+0800"];
    
    
    self.dataPicker.datePickerMode = UIDatePickerModeDateAndTime;
    [self.view addSubview:self.dataPicker];
}

- (void)drawButton {
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(130, 350, 100, 50)];
    button.backgroundColor = [UIColor orangeColor];
    [button setTitle:@"Remind me!" forState:UIControlStateNormal];
    [self.view addSubview:button];
    
    [button addTarget:self action:@selector(remindMe:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)remindMe:(UIButton *)button {
    NSDate *data = self.dataPicker.date;
    NSTimeInterval timeZoneOffset = [[NSTimeZone systemTimeZone] secondsFromGMT];
    data = [data dateByAddingTimeInterval:timeZoneOffset];
    NSLog(@"Setting a reminder for %@", data);
    
//    UNNotificationRequest *request = [[UNNotificationRequest alloc] init];
    
    UILocalNotification *note = [[UILocalNotification alloc] init];
    note.alertBody = @"Hypnotize me !";
    note.fireDate = data;
    note.timeZone = [NSTimeZone systemTimeZone];
    
    [[UIApplication sharedApplication] scheduleLocalNotification:note];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
